﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace CC.Yacht
{
    [DataContract]
    public class GameState : Game, IComparable<GameState>, IEquatable<GameState>
    {
        #region Constructor
        public GameState()
        {
            Dice = new Dice(new[] { new Die(), new Die(), new Die(), new Die(), new Die() });
            Scorecards = new Dictionary<long, Scorecard>();
        }

        public GameState(Game game) : this()
        {
            GameId = game.GameId;
            IsStarted = game.IsStarted;
            Owner = game.Owner;
            Players = game.Players;
        }
        #endregion

        #region Public Properties
        [DataMember]
        public User CurrentUser { get; set; }

        [DataMember]
        public Dice Dice { get; set; }

        [DataMember]
        public Dictionary<long, Scorecard> Scorecards { get; set; }
        #endregion

        #region Public Methods
        public int CompareTo(GameState other)
        {
            int returnValue = -1;

            if (other != null)
            {
                returnValue = GameId.CompareTo(other.GameId);
            }

            return returnValue;
        }

        public bool Equals(GameState other)
        {
            bool returnValue = false;

            if (other != null)
            {
                returnValue = (GameId == other.GameId);
            }

            return returnValue;
        }

        public Game ToGame()
        {
            return new Game(GameId) { IsStarted = IsStarted, Owner = Owner, Players = Players };
        }
        #endregion
    }
}
